package com.medical.data.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
@EnableOpenApi
public class SwaggerConfig {

    @Value("${swagger.enable}")
    private Boolean enable;  //是否开启配置

    @Value("${swagger.title}")
    private String title;  //标题

    @Value("${swagger.version}")
    private String version;  //版本号

    @Value("${swagger.package}")
    private String basePackage;  //扫描的包

    @Value("${swagger.author.name}")
    private String name;  //作者名

    @Value("${swagger.author.email}")
    private String email;  //邮箱


    @Bean
    public Docket docket(){
        return new Docket(DocumentationType.OAS_30)
                .enable(enable)
                .apiInfo(apiInfo())
                .select()
                //.apis(RequestHandlerSelectors.withClassAnnotation(ApiOperation.class))
                .apis(RequestHandlerSelectors.basePackage(basePackage))
                .paths(PathSelectors.any())
                .build();
    }

    public ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                // 设置标题
                .title(title)
                // 描述
                .description("配置所有的接口文档")
                // 版本
                .version(version)
                //作者信息
                .contact(new Contact(name,null,email))
                .build();
    }
}
